package com.lamatek.tags.google;

import java.io.Serializable;

import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * GoogleMapEventTag
 * 
 * This class represents a &lt;googlemaps:event> tag. Developers should not
 * override this class.
 * 
 * @author Tom Cole
 * @version 0.40
 */
public class GoogleMapEventTag extends TagSupport implements Serializable {
    
    String url = null;
    String action = null;
    boolean asynchronous = false;
    /**
     * Overrides doStartTag() from TagSupport. Developers should not override
     * this method.
     */
    public int doStartTag() {
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapEventListener) {
                ((GoogleMapEventListener) tag.getParent()).addEvent(this);
                return SKIP_BODY;
            }
            tag = tag.getParent();
        }
        return SKIP_BODY;
    }
    /**
     * Returns a url pointing to the Object that is responsible for handling this event.
     * 
     * @return A URL string.
     */
    public String getUrl() {
        return url;
    }
    /**
     * Sets the url to the Object responsible for handling this event. The Object
     * this url points to should implement the GoogleMapEventHandler interface.
     * 
     * @param url The url that points to a GoogleMapEventHandler.
     */
    public void setUrl(String url) {
        this.url = url;
    }
    /**
     * Returns the action name that this event handles. Options vary depending on 
     * the component this is added to. The complete list is:
     * <ul>
     * <li>click</li>
     * <li>dblclick</li>
     * <li>moveend</li>
     * <li>zoom</li>
     * <li>maptypechanged</li>
     * </ul>
     * 
     * @return The action name for this event.
     */
    public String getAction() {
        return action;
    }
    /**
     * Sets the action name that this event handles. Options vary depending on 
     * the component this is added to. The complete list is:
     * <ul>
     * <li>click</li>
     * <li>dblclick</li>
     * <li>moveend</li>
     * <li>zoom</li>
     * <li>maptypechanged</li>
     * <li>dragstart</li>
     * <li>dragend</li>
     * </ul>
     * 
     * @return The action name for this event.
     */
    public void setAction(String action) {
        this.action = action;
    }
    /**
     * Denotes whether or not this event is to be handled asynchronously (through
     * a GXmlHttp object) or synchronously (through a standard HTTP request.
     * 
     * Asynchronous events do not affect or update the page, they simply send data
     * to the GoogleMapEventHandler that is referred to by this event's url. This 
     * default behaviour is handled by the GoogleMapEventHandler if is has been
     * subclassed properly. These are data only events.
     * 
     * Synchronous events will reload the page, allowing the developer to add or
     * remove markers, events, etc. before the map is re-rendered. These are for
     * dynamic additions/subtractions from a map.
     * 
     * @returns True if this event is asynchronous, false if it is not.
     */
    public boolean isAsynchronous() {
        return asynchronous;
    }
    /**
     * Sets whether or not this event is to be handled asynchronously (through
     * a GXmlHttp object) or synchronously (through a standard HTTP request.
     * 
     * Asynchronous events do not affect or update the page, they simply send data
     * to the GoogleMapEventHandler that is referred to by this event's url. This 
     * default behaviour is handled by the GoogleMapEventHandler if is has been
     * subclassed properly. These are data only events.
     * 
     * Synchronous events will reload the page, allowing the developer to add or
     * remove markers, events, etc. before the map is re-rendered. These are for
     * dynamic additions/subtractions from a map.
     * 
     * @param asynchronous True if this event is asynchronous, false if it is not.
     */
    public void setAsynchronous(boolean asynchronous) {
        this.asynchronous = asynchronous;
    }
}
